﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using YaAppoint.DeviceTypes;

namespace YaAppoint.Web.Controllers
{
    public class DeviceTypeController(IDeviceTypeAppService deviceTypeAppService) : AbpController
    {
        private readonly IDeviceTypeAppService _deviceTypeAppService = deviceTypeAppService;

        /// <summary>
        /// 获取列表
        /// </summary>
        [HttpGet("/api/device-type/get-list")]
        public async Task<IActionResult> GetListAsync(string? filterName)
        {
            return new JsonResult( await _deviceTypeAppService.GetListAsync(filterName));
        }

        /// <summary>
        /// 获取单个
        /// </summary>
        [HttpGet("/api/device-type/get")]
        public async Task<IActionResult> GetAsync(Guid id)
        {
            return new JsonResult(await _deviceTypeAppService.GetAsync(id));
        }

        /// <summary>
        /// 删除多个
        /// </summary>
        [HttpPost("/api/device-type/delete-many")]
        public async Task<IActionResult> DeleteManyAsync([FromBody]List<Guid> idList)
        {
            return new JsonResult(await _deviceTypeAppService.DeleteAsync(idList));
        }

        /// <summary>
        /// 删除单个
        /// </summary>
        [HttpGet("/api/device-type/delete")]
        public async Task<IActionResult> DeleteAsync(Guid id)
        { 
            List<Guid> idList = new List<Guid>();
            idList.Add(id);
            return new JsonResult(await _deviceTypeAppService.DeleteAsync(idList));
        }

        [HttpPost("/api/device-type/edit-submit")]
        public async Task<IActionResult> EditSubmit([FromBody] DeviceTypeDto dto)
        {
            return new JsonResult(await _deviceTypeAppService.EditSubmit(dto));
        }

        [HttpPost("/api/device-type/create-submit")]
        public async Task<IActionResult> CreateSubmit([FromBody] CreateDeviceTypeDto dto)
        {
            return new JsonResult(await _deviceTypeAppService.CreateSubmit(dto));
        }
    }
}
